home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-27 | 33.7 KB | 1,051 lines | [TEXT/KAHL] |
- // -----------------------------------------------------------------------------
- // File : demoDialog.c
- // Date : August 24, 1994
- // Author : Jim Stout
- // Purpose : A demonstration routine for :
- // - my collection of CDEF's
- // - dialogAssist.c dialog utilities
- // - panelAssist.c tabPanel CDEF handling
- // - movableModal.c dialog routines
- //
- // Note the special usage of dim text routines required when using
- // AppendDITL and ShortenDITL routines. See file dimText.c.
- //
- // This demo uses the "TabPanel" CDEF - see "About CDEF's…".
- //
- // -----------------------------------------------------------------------------
- #include <GestaltEqu.h>
- #include <stdio.h>
-
- // demo routines
- #include "demoWind.h"
- #include "demoDialog.h"
-
- // utility routines
-
- #include "dialogAssist.h"
- #include "dimText.h"
- #include "panelAssist.h"
- #include "movableModal.h"
- #include "TogLib.h"
-
- // cdef #defines
-
- #include "jimsCDEF.h"
-
- //=============================================================================
- // number of controls on each panel
- //=============================================================================
- #define BUTTONCNT 14
- #define POPUPCNT 6
- #define SPINNERCNT 8
- #define DATECNT 6
- #define HSLIDERCNT 10
- #define VSLIDERCNT 6
- #define PROGBARCNT 9
- #define POPEXTCNT 9
-
- //=============================================================================
- // demoDialog globals - temporary storage for control values
- //=============================================================================
-
- short gFontNum, gFontSize;
- short gButtonValues[BUTTONCNT];
- short gPopUpValues[POPUPCNT];
- short gSpinnerValues[SPINNERCNT];
- long gDateValues[DATECNT];
- short gHSliderValues[HSLIDERCNT];
- short gVSliderValues[VSLIDERCNT];
- short gProgressValues[PROGBARCNT];
- short gPopExtensions[POPEXTCNT];
-
- ControlActionUPP gTrackSlider,gTrackSpin,gFractSpin;
-
- extern SysEnvRec gSysEnv;
- //=============================================================================
- // demo the tab dialog panel
- //=============================================================================
- extern void demoDialog()
- {
-
- DialogPtr theDialog;
- ModalFilterUPP filterUPP;
- GrafPtr savePort;
- short itemHit, inx, currPanel=0,toPanel;
- Boolean dimIt = true;
-
- //-----------------------------------------------------------------------------
- // Make sure we have the DITL extensions we need for the PanelSwap()
- // routine. These extensions are present in System 7 but require the
- // CommToolbox under System 6.
- //
- // If you want to use the DITL extensions under System 6, make sure
- // you include the CommToolbox libraries and call InitCRM() and
- // InitCTBUtilities() after initializing the toolbox.
- //-----------------------------------------------------------------------------
-
- if(daGestalt(gestaltDITLExtAttr) == -1L) {
- if(daGestalt(gestaltCTBVersion) < 0x0100) {
- StopAlert(256, nil);
- return;
- }
- }
-
- //-----------------------------------------------------------------------------
- // Create our UniversalProcPtr's
- //-----------------------------------------------------------------------------
- filterUPP = NewModalFilterProc(filter);
- if(filterUPP == nil) // a "real" program would
- return; // probably check these too..
-
- gTrackSlider = NewControlActionProc(trackSlider);
- gTrackSpin = NewControlActionProc(trackSpin);
- gFractSpin = NewControlActionProc(fractSpin);
-
- //-----------------------------------------------------------------------------
- // Create the dialog
- //-----------------------------------------------------------------------------
- theDialog = GetNewDialog(128,0L,(DialogPtr)-1);
- if(theDialog) {
- GetPort(&savePort);
- SetPort(theDialog);
-
- if(!gSysEnv.hasColorQD)
- HideControl(daGetCtlHandle(theDialog, BGCOLOR));
-
- initDimText(theDialog); // set up for dimmable text
-
- //-----------------------------------------------------------------------------
- // initialize the dialog to the correct panel
- //-----------------------------------------------------------------------------
-
- toPanel = daGetCtlValue(theDialog, TABCNTL);
-
- disposeDimData(theDialog);
- if(!panelSwap(theDialog, 128, currPanel, toPanel, STDCTLS))
- goto cleanUp;
- makeDimmable(theDialog);
-
- //-----------------------------------------------------------------------------
- // a "real" application would probably get control settings from some sort
- // of configuration file/record/structure. We'll just initialize our stuff
- // by calling savePanel() which will take the values from the CNTL templates.
- //-----------------------------------------------------------------------------
-
- savePanel(theDialog, toPanel);
-
- //-----------------------------------------------------------------------------
- // need to to find "Chicago" in the font popup, or we will start out with the
- // first font in the popup. Want to start with the standard system font.
- //-----------------------------------------------------------------------------
-
- if(toPanel == BUTTONS) {
- gFontNum = systemFont;
- gFontSize = 0;
- gButtonValues[12] = 12;
- gButtonValues[13] = findSystemFont(theDialog);
- }
-
- //-----------------------------------------------------------------------------
- // restore control settings and initialize the panel.
- //-----------------------------------------------------------------------------
-
- restorePanel(theDialog, toPanel);
- currPanel = toPanel;
-
- //-----------------------------------------------------------------------------
- // show the dialog and start handling events
- //-----------------------------------------------------------------------------
-
- ShowWindow(theDialog);
-
- do {
-
- // ModalDialog (filterUPP, &itemHit);
- movableModalDialog (filterUPP,&itemHit);
-
- //-----------------------------------------------------------------------------
- // a click on a tab, change to that panel
- //-----------------------------------------------------------------------------
-
- if(itemHit == TABCNTL) {
-
- toPanel = daGetCtlValue(theDialog, TABCNTL);
-
- if(toPanel != currPanel) {
-
- //-----------------------------------------------------------------------------
- // save settings of current panel first
- //-----------------------------------------------------------------------------
-
- savePanel(theDialog, currPanel);
-
- //-----------------------------------------------------------------------------
- // switch to the new panel and restore/initialize it. Since we are using
- // the dimText.c routines with AppendDITL, dispose of the dim data stuff.
- //-----------------------------------------------------------------------------
-
- disposeDimData(theDialog);
- if(!panelSwap(theDialog, 128, currPanel, toPanel, STDCTLS))
- goto cleanUp;
- makeDimmable(theDialog);
-
- restorePanel(theDialog, toPanel);
-
- currPanel = toPanel;
-
- //-----------------------------------------------------------------------------
- // re-enable the Disable/Enable button if needed
- //-----------------------------------------------------------------------------
-
- if(!dimIt) {
- daDimOne(theDialog, DISABLE, false);
- daSetCtlTitle(theDialog, DISABLE, "\pDisable");
- dimIt = true;
- }
- }
- }
- else
-
- //-----------------------------------------------------------------------------
- // show what the disabled controls look like
- //-----------------------------------------------------------------------------
-
- if(itemHit == DISABLE) {
- if(dimIt)
- daSetCtlTitle(theDialog, DISABLE, "\pEnable");
- else
- daSetCtlTitle(theDialog, DISABLE, "\pDisable");
- inx = CountDITL(theDialog);
- daDimItems(theDialog, STDCTLS+1, inx, dimIt);
- dimIt = !dimIt;
- if(currPanel == BUTTONS)
- daDimOne(theDialog, PB1, true);
- }
- else
- if(itemHit == BGCOLOR)
- changeBGColor(theDialog);
- else
- if(itemHit == BGPAT)
- changeBGPat(theDialog, true);
-
- //-----------------------------------------------------------------------------
- // handle a click on some other control within the panel
- //-----------------------------------------------------------------------------
-
- processPanel(theDialog, currPanel, itemHit);
-
- }while(itemHit != ok && itemHit != cancel);
-
- if(itemHit == ok) {
- // savePanel(theDialog, currPanel);
-
- //-----------------------------------------------------------------------------
- // some code to apply the temporary storage control values
- // in your application could go here.
- //-----------------------------------------------------------------------------
-
- }
- cleanUp:
- disposeDimText(theDialog);
- DisposDialog(theDialog);
- DisposeRoutineDescriptor(gTrackSlider);
- DisposeRoutineDescriptor(gTrackSpin);
- DisposeRoutineDescriptor(gFractSpin);
- DisposeRoutineDescriptor(filterUPP);
-
- SetPort(savePort);
- }
- }
-
- //=============================================================================
- // Handle a click on a control
- //=============================================================================
- static void processPanel(DialogPtr theDialog, short currPanel, short itemHit)
- {
- ControlHandle h;
- short t;
- Rect r;
- long num, newSize;
- Str255 fontSize;
- unsigned long secs;
- popUpPrivateDataH hPpd;
-
- switch (currPanel) {
- case BUTTONS:
- switch(itemHit) {
- case CB1: // click on a checkBox
- case CB2:
- case CB3:
- case CB4:
- daToggleCheck(theDialog, itemHit);
- resetTogButtons(theDialog,TB1);
- break;
- case RB1: // click on a radioButton
- case RB2:
- case RB3:
- case RB4:
- daToggleRadio(theDialog, itemHit, RB1, RB4);
- resetTogButtons(theDialog,TB1);
- break;
- case TB1: // click on a TogButton
- case TB2:
- case TB3:
- case TB4:
- setTogButtons(theDialog, itemHit, TB1, TB4);
- break;
- case EDITSIZE: // keydown in edit text
- num = daGetINum(theDialog, EDITSIZE);
- adjustSizePopup(theDialog, num);
- resetTogButtons(theDialog,TB1);
- break;
- case SIZEPOP:
- GetDItem(theDialog,SIZEPOP,&t,(Handle *)&h,&r);
- hPpd = (popUpPrivateDataH)(*h)->contrlData;
-
- newSize = GetCtlValue(h);
- GetItem((*hPpd)->mHandle, newSize, fontSize);
- daSetIText(theDialog, EDITSIZE, fontSize);
- daSelIText(theDialog, EDITSIZE);
- resetTogButtons(theDialog,TB1);
- break;
- case SETFONT:
- setNewFont(theDialog);
- resetTogButtons(theDialog,TB1);
- break;
- }
- break;
-
- //-----------------------------------------------------------------------------
- // set the value of the arrow control to match the edit text item
- //-----------------------------------------------------------------------------
-
- case SPINNERS:
- if(itemHit == EDITSPIN) {
- num = daGetINum(theDialog, EDITSPIN);
- daSetCtlValue(theDialog, SPIN3, (short)num);
- }
- break;
-
- //-----------------------------------------------------------------------------
- // reset the date time controls if RESET button clicked
- //-----------------------------------------------------------------------------
-
- case DATETIME:
- if(itemHit == RESET) {
- GetDateTime(&secs); // new date/time
- for(t=1;t<=6;t++) {
- h = daGetCtlHandle(theDialog, t+STDCTLS);
- if(h) {
- SetCRefCon(h, secs); // tell control about it
- InvalRect(&(**h).contrlRect); // force redraw
- }
- }
- }
- break;
-
- //-----------------------------------------------------------------------------
- // show how a spinner control can adjust a progress bar control
- //-----------------------------------------------------------------------------
-
- case PROGBARS:
- if(itemHit == SPIN10) {
- daSetCtlValue(theDialog, PROG9,
- daGetCtlValue(theDialog, SPIN10));
- }
- break;
-
- //-----------------------------------------------------------------------------
- // we don't do any special processing here for the other control examples,
- // but we do some special stuff for sliders via SetControlAction.
- //-----------------------------------------------------------------------------
-
- case POPUPS:
- break;
- case HSLIDERS:
- break;
- case VSLIDERS:
- break;
- }
- }
- //=============================================================================
- // A sample routine to show one method of saving the settings of the controls
- // on a panel. When a panel is "dismissed", the Dialog Manager disposes of the
- // controls on the panel, so we have to save the values to restore if the panel
- // is displayed again.
- //
- // This is pretty "brute force" - just some global arrays of control values.
- //
- //=============================================================================
- static void savePanel(DialogPtr theDialog, short currPanel)
- {
- short inx;
-
- switch (currPanel) {
- case BUTTONS:
- for(inx=1;inx<=BUTTONCNT-2;inx++)
- gButtonValues[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- gButtonValues[12] = daGetINum(theDialog, EDITSIZE);
- gButtonValues[13] = daGetCtlValue(theDialog, FONTPOP);
- break;
- case POPUPS:
- for(inx=1;inx<=POPUPCNT;inx++)
- gPopUpValues[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- break;
- case SPINNERS:
- for(inx=1;inx<=SPINNERCNT;inx++)
- gSpinnerValues[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- break;
- case DATETIME:
- for(inx=1;inx<=DATECNT;inx++)
- gDateValues[inx-1] = daGetCtlRefCon(theDialog, inx+STDCTLS);
- break;
- case HSLIDERS:
- for(inx=1;inx<=HSLIDERCNT;inx++)
- gHSliderValues[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- break;
- case VSLIDERS:
- for(inx=1;inx<=VSLIDERCNT;inx++)
- gVSliderValues[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- break;
- case PROGBARS:
- for(inx=1;inx<=PROGBARCNT;inx++)
- gProgressValues[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- break;
- case POPUPEXT:
- for(inx=1;inx<=POPEXTCNT;inx++)
- gPopExtensions[inx-1] = daGetCtlValue(theDialog, inx+STDCTLS);
- break;
- }
- }
-
- //=============================================================================
- // A sample routine to show one method of restoring the control settings to
- // proper values when a panel is shown by clicking on its tab.
- //
- // This routine also does some special initialization of controls.
- //=============================================================================
- static void restorePanel(DialogPtr theDialog, short toPanel)
- {
- ControlHandle ch;
- SpinHandle hSpin;
- short inx;
-
- switch(toPanel) {
-
- case BUTTONS:
-
- //-----------------------------------------------------------------------------
- // set font & restore control values
- //-----------------------------------------------------------------------------
-
- changeFont(theDialog, gFontNum, gFontSize);
- for(inx=1;inx<=BUTTONCNT-2;inx++)
- daSetCtlValue(theDialog, inx+STDCTLS, gButtonValues[inx-1]);
-
- //-----------------------------------------------------------------------------
- // set font controls
- //-----------------------------------------------------------------------------
-
- daSetINum(theDialog, EDITSIZE, gButtonValues[12]);
- adjustSizePopup(theDialog, gButtonValues[12]);
- daSetCtlValue(theDialog, FONTPOP, gButtonValues[13]);
-
- //-----------------------------------------------------------------------------
- // initialize the Tog buttons and disable one button
- //-----------------------------------------------------------------------------
-
- initTogButtons(theDialog, TB1,TB4);
- daDimOne(theDialog, PB1, true);
- break;
-
- case POPUPS:
-
- //-----------------------------------------------------------------------------
- // set font & restore control values
- //-----------------------------------------------------------------------------
-
- changeFont(theDialog, geneva, 9);
- for(inx=1;inx<=POPUPCNT;inx++)
- if(gPopUpValues[inx-1])
- daSetCtlValue(theDialog, inx+STDCTLS, gPopUpValues[inx-1]);
- break;
-
- case SPINNERS:
-
- //-----------------------------------------------------------------------------
- // set font & restore control values
- //-----------------------------------------------------------------------------
-
- changeFont(theDialog, 0, 0); // since there is an edit field
-
- for(inx=1;inx<=SPINNERCNT;inx++)
- daSetCtlValue(theDialog, inx+STDCTLS, gSpinnerValues[inx-1]);
-
- //-----------------------------------------------------------------------------
- // initialize edit text item to the value of the 3rd spinner
- //-----------------------------------------------------------------------------
-
- daSetINum(theDialog, EDITSPIN,
- daGetCtlValue(theDialog, SPIN3));
- SelIText(theDialog, EDITSPIN, 32768, 32768);
-
- //-----------------------------------------------------------------------------
- // the 6th spinner will adjust by 0.10, so stash a divisor value of 10
- // in the userData field
- //-----------------------------------------------------------------------------
-
- ch = daGetCtlHandle(theDialog, SPIN7);
- if(ch) {
- hSpin = (SpinHandle)(**ch).contrlData;
- (**hSpin).userData = 10;
- fractSpin(ch, 1); // draw the value
- }
-
- break;
-
- case DATETIME:
-
- //-----------------------------------------------------------------------------
- // set font & restore control values
- //-----------------------------------------------------------------------------
-
- changeFont(theDialog, geneva, 9);
- for(inx=1;inx<=DATECNT;inx++)
- daSetCtlRefCon(theDialog, inx+STDCTLS, gDateValues[inx-1]);
- break;
-
- case HSLIDERS:
-
- //-----------------------------------------------------------------------------
- // set font & restore control values
- //-----------------------------------------------------------------------------
-
- changeFont(theDialog, geneva, 9);
- for(inx=1;inx<=HSLIDERCNT;inx++)
- daSetCtlValue(theDialog, inx+STDCTLS, gHSliderValues[inx-1]);
-
- //-----------------------------------------------------------------------------
- // set a ctlAction proc for slider 3
- //-----------------------------------------------------------------------------
-
- ch = daGetCtlHandle(theDialog, HSLIDER3);
- SetCtlAction(ch, (ControlActionUPP)gTrackSlider);
- daSetINum(theDialog, HSLIDERVAL3, GetCtlValue(ch));
-
-
- ch = daGetCtlHandle(theDialog, HSLIDER9);
- SetCtlAction(ch, (ControlActionUPP)gTrackSlider);
- daSetINum(theDialog, HSLIDERVAL9, GetCtlValue(ch));
- break;
-
- case VSLIDERS:
- changeFont(theDialog, geneva, 9);
-
- //-----------------------------------------------------------------------------
- // restore control values
- //-----------------------------------------------------------------------------
-
- for(inx=1;inx<=VSLIDERCNT;inx++)
- daSetCtlValue(theDialog, inx+STDCTLS, gVSliderValues[inx-1]);
-
- //-----------------------------------------------------------------------------
- // set a ctlAction proc for slider 5
- //-----------------------------------------------------------------------------
-
- ch = daGetCtlHandle(theDialog, VSLIDER5);
- SetCtlAction(ch, (ControlActionUPP)gTrackSlider);
- daSetINum(theDialog, VSLIDERVAL5, GetCtlValue(ch));
- break;
-
- case PROGBARS:
-
- //-----------------------------------------------------------------------------
- // set font & restore control values
- //-----------------------------------------------------------------------------
-
- changeFont(theDialog, geneva, 9);
- for(inx=1;inx<=PROGBARCNT;inx++)
- daSetCtlValue(theDialog, inx+STDCTLS, gProgressValues[inx-1]);
- break;
- case POPUPEXT:
- changeFont(theDialog, 0, 0);
- for(inx=1;inx<=POPEXTCNT;inx++)
- daSetCtlValue(theDialog, inx+STDCTLS, gPopExtensions[inx-1]);
- break;
- }
- }
- //=============================================================================
- // a simple dialog filter proc
- //=============================================================================
- static pascal char filter(DialogPtr theDialog, EventRecord *theEvent, short *theItem)
- {
- char result = FALSE;
- char c;
- short panelNum=0,inx,editItem,partCode;
- long min,max;
- ControlHandle cHdl;
- Point mousePt;
-
- panelNum = daGetCtlValue(theDialog, TABCNTL);
-
- switch(theEvent->what) {
-
- case nullEvent:
-
- //-----------------------------------------------------------------------------
- // for this demo program, we'll use null events to demo the progress bar
- // cdefs on panel 7 of the dialog
- //-----------------------------------------------------------------------------
-
- if(panelNum == PROGBARS) {
- for(inx=STDCTLS+1;inx<=STDCTLS+8;inx++) {
- daSetCtlValue(theDialog, inx,
- daGetCtlValue(theDialog, inx)+1);
- if(daGetCtlValue(theDialog, inx) >= daGetCtlMax(theDialog, inx))
- daSetCtlValue(theDialog, inx, 0);
- }
- }
- break;
-
- case keyDown:
- case autoKey:
-
- //-----------------------------------------------------------------------------
- // for this demo, we'll show how to use command or control key
- // combinations to operate the tabPanel CDEF
- //-----------------------------------------------------------------------------
-
- c = theEvent->message & charCodeMask;
-
- if(theEvent->modifiers & cmdKey) {
- result = panelCmdKey(theDialog, TABCNTL, c, theItem);
- if(result)
- break;
- }
- if(theEvent->modifiers & controlKey ||
- theEvent->modifiers & cmdKey) {
- result = panelCmdTab(theDialog, TABCNTL, c, theItem);
- if(result)
- break;
- }
-
- //-----------------------------------------------------------------------------
- // handle a forward delete key
- //-----------------------------------------------------------------------------
-
- result = daForwardDel(theDialog, c);
- if(result)
- break;
- if(theEvent->modifiers & shiftKey) {
- result = daShiftSelect(theDialog, c);
- if(result)
- break;
- }
- editItem = ((DialogPeek)theDialog)->editField + 1;
-
- //-----------------------------------------------------------------------------
- // limit to numeric entry only
- //-----------------------------------------------------------------------------
-
- if(panelNum == BUTTONS && editItem == EDITSIZE) {
- result = daEnterNumber(theDialog, editItem, 0L, 18L, c);
- }
- else
- if(panelNum == SPINNERS) {
- max = daGetCtlMax(theDialog, SPIN3);
- min = daGetCtlMin(theDialog, SPIN3);
- result = daEnterNumber(theDialog, editItem, min, max, c);
- }
- break;
-
- case mouseDown:
- mousePt = theEvent->where;
- GlobalToLocal(&mousePt);
- partCode = FindControl(mousePt, theDialog, &cHdl);
-
- //-----------------------------------------------------------------------------
- // demonstrate use of FindControl/TrackControl within a dialog and to show
- // how to continuously update the progress bar (item #10) from the value
- // of the spinner (item #9)
- //-----------------------------------------------------------------------------
-
- if(panelNum == PROGBARS) {
- if(partCode && cHdl == daGetCtlHandle(theDialog, SPIN10)) {
- TrackControl(cHdl, mousePt, (ControlActionUPP)gTrackSpin);
- }
- }
- else
-
- //-----------------------------------------------------------------------------
- // spinner 7 is a control that adjusts by a fractional value
- //-----------------------------------------------------------------------------
-
- if(panelNum == SPINNERS) {
- if(partCode && cHdl == daGetCtlHandle(theDialog, SPIN7)) {
- TrackControl(cHdl, mousePt, (ControlActionUPP)gFractSpin);
- }
- }
-
- break;
- }
- return result;
- }
- //=============================================================================
- // A simple action proc for call to TrackControl above. Just sets the value
- // of the progress bar to match the spinner.
- //=============================================================================
- static pascal void trackSpin(ControlHandle theControl, short partCode)
- {
- DialogPtr theDialog = (**theControl).contrlOwner;
-
- if(partCode) {
- daSetCtlValue(theDialog, PROG9, GetCtlValue(theControl));
- }
- }
- //=============================================================================
- // This routine is set as an actionProc via SetCtlAction to provide
- // "live" display of the values of a Slider control.
- // It simply displays the control value as a statText item (using daSetINum).
- //
- // This one function is handling 3 different slider controls.
- //=============================================================================
- static pascal void trackSlider(ControlHandle theControl, short partCode)
- {
- DialogPtr theDialog = (**theControl).contrlOwner;
-
- if(partCode) {
- if(theControl == daGetCtlHandle(theDialog, VSLIDER5))
- daSetINum(theDialog, VSLIDERVAL5, GetCtlValue(theControl));
- else
- if(theControl == daGetCtlHandle(theDialog, HSLIDER3))
- daSetINum(theDialog, HSLIDERVAL3, GetCtlValue(theControl));
- else
- if(theControl == daGetCtlHandle(theDialog, HSLIDER9))
- daSetINum(theDialog, HSLIDERVAL9, GetCtlValue(theControl));
- }
- }
- //=============================================================================
- // This Action proc shows how to have a spinner control with a fractional
- // increment
- //=============================================================================
- static pascal void fractSpin(ControlHandle theControl, short partCode)
- {
- DialogPtr theDialog;
- short val,div;
- ControlHandle hCtrl;
- SpinHandle hSpin;
- Str255 s;
- double dbl;
-
- if(!partCode) // avoid flicker
- return;
-
- theDialog = (**theControl).contrlOwner;
-
- //-----------------------------------------------------------------------------
- // grab the handle to the control, extract the userData value
- // to use as divisor to calculate the value to display in the text item
- //-----------------------------------------------------------------------------
-
- hCtrl = daGetCtlHandle(theDialog, SPIN7);
- if(theControl == hCtrl) {
- hSpin = (SpinHandle)(**theControl).contrlData;
- div = (**hSpin).userData;
-
- val = GetCtlValue(hCtrl);
- dbl = (double)val/div;
- sprintf((char *)s, "%3.1lf", dbl);
- c2pstr((char *)s);
-
- //-----------------------------------------------------------------------------
- // display the calcuated value (in this case, via a statText item)
- //-----------------------------------------------------------------------------
-
- daSetIText(theDialog, FRACTSPIN, s);
- }
-
- }
-
- //=============================================================================
- // A rather simple minded routine to change the background color of the
- // dialog - to demonstrate how the controls look on various backgrounds.
- //=============================================================================
- static void changeBGColor (DialogPtr theDialog)
- {
- short cInx,inx,max;
- long bg[]={-1, 0xEEEE, 0xDDDD, 0xCCCC, 0xBBBB, 0xAAAA};
- // long bg[]={-1, 0xAAAA, 0xCCCC, 0xDDDD, 0xEEEE};
- AuxWinHandle aux;
- GrafPtr savePort;
-
- GetPort(&savePort);
-
- cInx = daGetCtlValue(theDialog, BGCOLOR) -1; // get menu setting
-
- GetAuxWin(theDialog, &aux); // current colors
- if(aux) {
- max = (**(**aux).awCTable).ctSize; // look for content color
- for(inx=0;inx<max;inx++) { // entry & change it.
-
- if((**(**aux).awCTable).ctSeed == wContentColor) {
- (**(**aux).awCTable).ctTable[inx].rgb.red = bg[cInx];
- (**(**aux).awCTable).ctTable[inx].rgb.green = bg[cInx];
- (**(**aux).awCTable).ctTable[inx].rgb.blue = bg[cInx];
- if(daGetCtlValue(theDialog, BGPAT) > 0) {
- daSetCtlValue(theDialog, BGPAT, 0);
- changeBGPat(theDialog, false);
- }
- SetWinColor(theDialog, (WCTabHandle)(**aux).awCTable);
- SetPort(theDialog); // do this or die..
- break;
- }
- }
- }
- SetPort(savePort);
- }
-
- //=============================================================================
- // Change the background pattern for the dialog
- //=============================================================================
- static void changeBGPat (DialogPtr theDialog, Boolean redraw)
- {
- short cInx;
- PixPatHandle pixPat=nil;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(theDialog);
-
- cInx = daGetCtlValue(theDialog, BGPAT) -1; // get menu setting
-
- if(cInx)
- pixPat = GetPixPat(cInx+128);
-
- if(pixPat) {
- BackPixPat(pixPat);
- }
- else {
- BackPat(&qd.white);
- }
- if(redraw) {
- InvalRect(&theDialog->portRect);
- }
-
- SetPort(savePort);
- }
-
- //=============================================================================
- // Get font & font size info from panel 1 controls and use to change font.
- //=============================================================================
- static void setNewFont (DialogPtr theDialog)
- {
- ControlHandle h=0;
- short t, val, newFont;
- Rect r;
- long newSize;
- Str255 fontName, fontSize;
- GrafPtr thisPort;
- popUpPrivateDataH hPpd=0;
-
- //-----------------------------------------------------------------------------
- // get the font size from the popup menu
- //-----------------------------------------------------------------------------
-
- GetDItem(theDialog,SIZEPOP,&t,(Handle *)&h,&r);
- if(h) {
- val = GetCtlValue(h);
- hPpd = (popUpPrivateDataH)(*h)->contrlData;
- if(hPpd) {
- GetItem((*hPpd)->mHandle, val, fontSize);
- StringToNum(fontSize, &newSize);
- if(newSize == 12)
- newSize = 0;
- }
- }
-
- //-----------------------------------------------------------------------------
- // get the font from the popup menu
- //-----------------------------------------------------------------------------
-
- GetDItem(theDialog,FONTPOP,&t,(Handle *)&h,&r);
- if(h) {
- val = GetCtlValue(h);
- hPpd = (popUpPrivateDataH)(*h)->contrlData;
- if(hPpd) {
- GetItem((*hPpd)->mHandle, val, fontName);
- GetFNum(fontName, &newFont);
-
- changeFont(theDialog, newFont, newSize);
-
- GetPort(&thisPort);
- gFontNum = thisPort->txFont;
- gFontSize = thisPort->txSize;
- }
- }
- //-----------------------------------------------------------------------------
- // redraw the dialog in the new font & size
- //-----------------------------------------------------------------------------
-
- DrawDialog(theDialog);
- }
-
- //=============================================================================
- // Set a new font for this dialog. This is a nasty way to do this,
- // but it appears to work.
- //=============================================================================
- static void changeFont(DialogPtr theDialog, short newFont, long newSize)
- {
- FontInfo fInfo;
-
- SetPort(theDialog);
-
- if(theDialog->txFont != newFont || // minimize flicker from
- theDialog->txSize != newSize) { // redrawing
-
- //-----------------------------------------------------------------------------
- // set new font & size for current port
- //-----------------------------------------------------------------------------
-
- TextFont(newFont);
- TextSize((short)newSize);
-
- //-----------------------------------------------------------------------------
- // set new font for TEHandle in dialog (this is a crude hack!)
- //-----------------------------------------------------------------------------
-
- GetFontInfo(&fInfo);
- (*((DialogPeek)theDialog)->textH)->txFont = newFont;
- (*((DialogPeek)theDialog)->textH)->txSize = newSize;
- (*((DialogPeek)theDialog)->textH)->fontAscent = fInfo.ascent;
- (*((DialogPeek)theDialog)->textH)->lineHeight =
- fInfo.ascent+fInfo.descent+fInfo.leading;
- }
- }
-
- //=============================================================================
- // Set a new size into the popup menu for font size. Called when the
- // EDITSIZE dialog edit item is changed, will add or remove a "custom" size
- // and a separator line as required.
- //=============================================================================
- static void adjustSizePopup (DialogPtr theDialog, long newSize)
- {
- short type,val,inx,max;
- long longVal;
- ControlHandle h;
- MenuHandle hMenu;
- Rect r;
- popUpPrivateDataH hPpd;
- Str255 s;
- Boolean found=false;
-
- GetDItem(theDialog,SIZEPOP,&type,(Handle *)&h,&r); // get menu handle
- hPpd = (popUpPrivateDataH)(*h)->contrlData;
- hMenu = (*hPpd)->mHandle;
-
- val = GetCtlValue(h); // uncheck current item
- CheckItem(hMenu, val, FALSE);
-
- max = CountMItems(hMenu); // number of menu items
-
- for(inx=1;inx<=max;inx++) { // see if typed in value
- GetItem(hMenu, inx, s); // matches a menu item
- StringToNum(s, &longVal);
- if(longVal == newSize) { // yep, got a match but it is
- if(inx > 2 & max > MAXFONTSIZES) { // not custom, so let's
- DelMenuItem(hMenu,1); // delete the custom setting
- DelMenuItem(hMenu,1); // and the separator line
- inx-=2;
- }
- CheckItem(hMenu, inx, TRUE); // check new item
- SetCtlValue(h, inx);
- found = true;
- break;
- }
- }
- if(!found) { // no match, set custom item
- NumToString(newSize, s);
- if(max == MAXFONTSIZES) { // add a custom value
- InsMenuItem(hMenu, "\p(-", 0); // first, a separator
- InsMenuItem(hMenu, s, 0); // now, the new size
- }
- else {
- SetItem(hMenu, 1, s); // replace existing custom
- }
- CheckItem(hMenu, 1, TRUE);
- SetCtlValue(h, 1);
- }
- }
-
- //=============================================================================
- // find the System font item in the popup menu created with AddResMenu
- //=============================================================================
- static short findSystemFont(DialogPtr theDialog)
- {
- Str255 fontName;
- ControlHandle hCtl;
- MenuHandle hMenu;
- short t,max,inx,newFont=2;
- Rect r;
- popUpPrivateDataH hPpd;
-
- GetDItem(theDialog, FONTPOP, &t, (Handle *)&hCtl, &r);
- if(hCtl) {
- hPpd = (popUpPrivateDataH)(*hCtl)->contrlData;
- hMenu = (*hPpd)->mHandle;
- if(hMenu) {
- max = CountMItems(hMenu);
-
- for(inx=1;inx<=max;inx++) {
- GetItem(hMenu, inx, fontName);
- GetFNum(fontName, &newFont);
- if(newFont == systemFont)
- break;
-
- }
- }
- }
- return(inx);
- }
-
- //=============================================================================
- // a simple side-by-side comparison between CDEF 63 (System 7) & CDEF 101
- //=============================================================================
- extern void comparePopup()
- {
- DialogPtr theDialog;
- GrafPtr savePort;
- short itemHit,inx,t;
- ControlHandle hCtl,hCtl2;
- Rect r;
-
- theDialog = GetNewDialog(259,0L,(DialogPtr)-1);
- if(theDialog) {
- GetPort(&savePort);
- SetPort(theDialog);
- TextFont(monaco);
- TextSize(9);
-
- ShowWindow(theDialog);
-
- do {
- movableModalDialog ((ModalFilterUPP)nil,&itemHit);
- if(itemHit == 3) { // disable button
- for(inx = 4;inx<=15;inx++) {
- GetDItem(theDialog, inx, &t, (Handle *)&hCtl, &r);
- if((*hCtl)->contrlHilite == 0xff)
- HiliteControl(hCtl,0);
- else
- HiliteControl(hCtl,255);
- }
- GetDItem(theDialog, 3, &t,(Handle *)&hCtl2, &r);
- if((*hCtl)->contrlHilite == 0xff)
- SetCTitle(hCtl2, "\pEnable");
- else
- SetCTitle(hCtl2, "\pDisable");
- }
- }while(itemHit != ok && itemHit != cancel);
- DisposDialog(theDialog);
- SetPort(savePort);
- }
- }